﻿using KaytechSoftware.Cms.App.Areas.Admin.Interfaces;
using KaytechSoftware.Cms.App.Areas.Admin.Models.Base;
using KaytechSoftware.Cms.App.Common;
using KaytechSoftware.Cms.Services.Dto;

namespace KaytechSoftware.Cms.App.Areas.Admin.Models.Entities
{
    public class PhotoAlbumModel : GridEntityModel, IGridEntityModel<PhotoAlbumDto> 
    {
        [Id]
        [Label(ResourceKey = "Id")]
        [Renderer(Type = RendererType.Hidden)]
        public long Id { get; set; }

        [Label(ResourceKey = "MainPhoto")]
        [Renderer(Type = RendererType.Image)]
        [SkipInDetails]
        public PhotoDescriptor MainPhoto { get; set; }

        [Label(ResourceKey = "Title")]
        [Renderer(Type = RendererType.TextBox)]
        [ActionLink(Action =  "PhotoList")]
        public string Title { get; set; }

        [Label(ResourceKey = "Description")]
        [Renderer(Type = RendererType.TextArea)]
        public string Description { get; set; }

        [Label(ResourceKey = "Page")]
        [Renderer(Type = RendererType.DropDown, UseCollection = CollectionKey.Page)]
        [SkipInGrid]
        public long PageId { get; set; }

        [Label(ResourceKey = "Page")]
        [Renderer(Type = RendererType.TextBox)]
        [SkipInDetails]
        public string Page { get; set; }

        public GridEntityModel FromDto(PhotoAlbumDto dto)
        {
            if (dto.MainPhotoId.HasValue && dto.MainPhotoVersion.HasValue)
                MainPhoto = new PhotoDescriptor { AlbumId = dto.Id, PhotoId = dto.MainPhotoId.Value, Version = dto.MainPhotoVersion.Value };

            Id = dto.Id;
            Title = dto.Title;
            Description = dto.Description;
            PageId = dto.PageId;
            Page = dto.PageTitle;
            return this;
        }

        public PhotoAlbumDto ToDto()
        {
            return new PhotoAlbumDto
            {
                Id = Id,
                Title = Title,
                Description = Description,
                PageId = PageId,
                PageTitle = Page
            };
        }
    }
}